package com.konne.nightmare.FastPublicOpinion.http;

import androidx.annotation.NonNull;

import com.konne.nightmare.FastPublicOpinion.utils.MMKVUtils;
import com.konne.nightmare.FastPublicOpinion.utils.Utils;
import com.socks.library.KLog;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class AddHeadInterceptor implements Interceptor{

    private String key;
    private String value;

    public AddHeadInterceptor(String key, String value) {
        this.key = key;
        this.value = value;
    }

    @NonNull
    @Override
    public Response intercept(Interceptor.Chain chain) throws IOException {
        Request original = chain.request();
        Request.Builder requestBuilder = original.newBuilder()
                .header("Content-Type", "application/json; charset=UTF-8")
                .addHeader("Connection", "close")
                .addHeader("Authorization", MMKVUtils.getMMKVString(Utils.TOKEN));

        HttpUrl url = requestBuilder.get().build().url();
        //对Url进行拼接，实现类似http://api.v2.yyj.cn/api/web/jcDataManage/info/1501341309这种傻逼URL
        requestBuilder.url(url + value);
        Request request = requestBuilder.build();
        return chain.proceed(request);
    }
}
